package com.wwy.arithmetic.suanfa;

import com.wwy.arithmetic.suanfa.entry.ListNode;
import lombok.Data;

/**
 * 翻转二叉树
 */
public class FanZhuanTree {

    @Data
    static class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;

        public TreeNode(int val) {
            this.val = val;
        }

        public TreeNode() {
        }
    }

    public static void main(String[] args) {
        TreeNode node = new TreeNode(1);
        TreeNode node1 = new TreeNode(2);
        TreeNode node2 = new TreeNode(3);
        TreeNode node3 = new TreeNode(4);
        TreeNode node4 = new TreeNode(5);
        TreeNode node5 = new TreeNode(6);
        node.left = node1;
        node.right = node2;
        node1.left = node3;
        node1.right = node4;
        node2.left = node5;
        System.out.println("node = " + node.toString());
        TreeNode treeNode = fanzhuanTree(node);
        System.out.println("treeNode = " + treeNode.toString());
    }

    static TreeNode fanzhuanTree(TreeNode node){
        if(node==null){
            return null;
        }
        TreeNode treeNode = node.left;
        node.left = node.right;
        node.right = treeNode;
        fanzhuanTree(node.left);
        fanzhuanTree(node.right);
        return node;
    }

}
